package com.cx.controller;

import com.cx.common.ApiReturn;
import com.cx.pojo.Imgdetails;
import com.cx.service.ImgDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("imgDetails")
@CrossOrigin//跨域
public class ImgDetailsController {

    @Autowired
    ImgDetailsService imgDetailsService;

    //添加图片
    @RequestMapping("insertImgdetails")
    @ResponseBody
    public ApiReturn insertImgdetails(Imgdetails imgdetails){
        int rows = imgDetailsService.insert(imgdetails);
        if (rows<1){
            return ApiReturn.error("添加失败");
        }
        return  ApiReturn.success("添加成功");
    }

    //修改图片
    @RequestMapping("updateImgdetails")
    @ResponseBody
    public ApiReturn updateImgdetails(Imgdetails imgdetails){
        int rows = imgDetailsService.updateByPrimaryKey(imgdetails);
        if (rows<1){
            return ApiReturn.error("修改失败");
        }
        return ApiReturn.success("修改成功");
    }

    //删除图片
    @RequestMapping("deleteImgdetails")
    @ResponseBody
    public ApiReturn deleteImgdetails(Integer imgId) {
        int rows = imgDetailsService.deleteByPrimaryKey(imgId);
        if (rows < 1) {
            return ApiReturn.error("删除失败");
        }
        return ApiReturn.success("删除成功");
    }

    //根据id查询图片
    @RequestMapping("selectImgdetailsById")
    @ResponseBody
    public ApiReturn selectImgdetailsById(Integer imgId) {
        Imgdetails imgdetailsInfo = imgDetailsService.selectByPrimaryKey(imgId);
        if (imgdetailsInfo != null) {
            return ApiReturn.success("图片数据详情",imgdetailsInfo);
        }
        return ApiReturn.error("未获取该图片数据详情");
    }
}
